package com.hxk.ioc.config;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;
import java.util.Objects;

/**
 * 自定义扫描过滤类
 */
public class MyTypeFilter implements TypeFilter {

    /**
     * 匹配方法
     * @param metadataReader 当前正在扫描的类信息
     * @param metadataReaderFactory 其它任何类的信息
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

        //获取当前类的注解信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        //获取当前扫描的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();

        //获取当前类的类资源
        Resource resource = metadataReader.getResource();

        //获取类名称
        String className = classMetadata.getClassName();

        System.out.println(">>>>>>>>>>>>>>>>>>>"+className);

        //过滤掉UserDao
        if(Objects.equals("com.hxk.ioc.dao.UserDao",className)){
            return true;
        }

        return false;
    }
}
